package com.hongsheng.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongsheng.mapper.GoodsMapper;
import com.hongsheng.pojo.Bill;
import com.hongsheng.pojo.Goods;
import com.hongsheng.pojo.vo.GoodsReportVo;
import com.hongsheng.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author admin
 * @version 1.0
 * @date 2023/8/10 18:46
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    @Override
    public List<Goods> findAll() {
//        PageHelper.startPage(1,1);
        return goodsMapper.findAll();
    }

    //查询所有订单id
    @Override
    public List<Integer> getAllOrderId() {
        return goodsMapper.getAllOrderId();
    }

    @Override
    public Boolean insertGoods(Goods goods) {
        return goodsMapper.insertGoods(goods)>0;
    }

    @Override
    public Goods findGoodsById(Integer id) {
        return goodsMapper.findGoodsById(id);
    }

    @Override
    public Boolean updateGoods(Goods goods) {
        return goodsMapper.updateGoods(goods)>0;
    }

    @Override
    public Boolean deleteGoods(Integer id) {
        return goodsMapper.deleteGoods(id);
    }

    @Override
    public Boolean getOrderStatusById(int id) {
        Integer status = goodsMapper.getOrderStatusById(id);
        return status < 3;
    }



    @Override
    public PageInfo<Goods> getPageGoods(Integer currentPage, Integer pageSize,Goods goods) {
        PageHelper.startPage(currentPage,pageSize);
        List<Goods> pageGoods = goodsMapper.getPageGoods("%"+goods.getName()+"%","%"+goods.getType()+"%","%"+goods.getNature()+"%");
        return new PageInfo<Goods>(pageGoods);

    }

    @Override
    public Double getCost(Integer id) {
        return goodsMapper.getCost(id);
    }

    @Override
    public Double getIncome(Integer id) {
        return goodsMapper.getIncome(id);
    }

    @Override
    public Boolean GoodsCost(Bill bill) {
        Integer integer = goodsMapper.GoodsCost(bill);
        if (integer >0) {
            return true;
        }
        return false;
    }

    @Override
    public Boolean GoodsIncome(Bill bill) {
        Integer integer = goodsMapper.GoodsIncome(bill);
        if (integer >0) {
            return true;
        }
        return false;
    }

    /**
     * 查询类型订单数量
     * @return
     */
    @Override
    public List<GoodsReportVo> selectGoodsByQuantity() {
        return goodsMapper.selectGoodsByQuantity();
    }

//    @Override
//    public Boolean getDriverStatusById(int id) {
//        Integer statusById = goodsMapper.getDriverStatusById(id);
//        return statusById <= 0;
//    }

}
